<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * Model untuk siswa
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class m_siswa extends CI_Model {

    function ambil($limit, $offset) {
        $query = $this->db->get('tb_siswa', $limit, $offset);
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $data) {
                $hasil[] = $data;
            }
            return $hasil;
        }
    }

    function edit($a) {
        $query = $this->db->get_where('tb_siswa', array('id_siswa' => $a))->row();
        return $query;
    }

    function tambah() {
        $no_induk = $this->input->post('no_induk');
        $nama = $this->input->post('nm_siswa');
        $pass = $this->input->post('pass');
        $data = array('id_siswa' => NULL,
            'nomor_induk' => $no_induk,
            'nama' => $nama,
            'password' => $pass);
        $this->db->insert('tb_siswa', $data);
    }

    function update($id) {

        $no_induk = $this->input->post('no_induk');
        $nama = $this->input->post('nm_siswa');
        $pass = $this->input->post('pass');
        $data = array('nomor_induk' => $no_induk,
            'nama' => $nama,
            'password' => $pass);
        $this->db->where('id_siswa', $id);
        $this->db->update('tb_siswa', $data);
    }

    function hapus($a) {
        $this->db->delete('tb_siswa', array('id_siswa' => $a));
        return;
    }

    function cari_like($kata) {
        $this->db->like('nama', $kata);
        $q = $this->db->get('tb_siswa');
        return $q;
    }

    function cari($kata, $limit, $offset) {
        $this->db->like('nama', $kata);
        $ambil = $this->db->get('tb_siswa', $limit, $offset);
        if ($ambil->num_rows() > 0) {
            foreach ($ambil->result() as $data) {
                $hasil[] = $data;
            }
            return $hasil;
        }
    }

    function login_siswa($no_induk, $pass) {
        $cek_login = $this->db->get_where('tb_siswa', array('nomor_induk' => $no_induk, 'password' => $pass));
        if (count($cek_login->result()) > 0) {
            foreach ($cek_login->result_array() as $data) {
                $hasil[] = $data;
            }
            return $hasil;
        } else {
            return false;
        }
    }

}

?>
